package com.example.mygreendao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.example.pingtools.bean.IpDataBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "IP_DATA_BEAN".
*/
public class IpDataBeanDao extends AbstractDao<IpDataBean, Long> {

    public static final String TABLENAME = "IP_DATA_BEAN";

    /**
     * Properties of entity IpDataBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Text = new Property(1, String.class, "text", false, "text");
        public final static Property Ip = new Property(2, String.class, "ip", false, "ip");
        public final static Property Port = new Property(3, String.class, "port", false, "port");
        public final static Property CustomId = new Property(4, Long.class, "customId", false, "customId");
    }

    private Query<IpDataBean> floderBean_IpDataBeansQuery;

    public IpDataBeanDao(DaoConfig config) {
        super(config);
    }
    
    public IpDataBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"IP_DATA_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"text\" TEXT," + // 1: text
                "\"ip\" TEXT," + // 2: ip
                "\"port\" TEXT," + // 3: port
                "\"customId\" INTEGER);"); // 4: customId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"IP_DATA_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, IpDataBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String text = entity.getText();
        if (text != null) {
            stmt.bindString(2, text);
        }
 
        String ip = entity.getIp();
        if (ip != null) {
            stmt.bindString(3, ip);
        }
 
        String port = entity.getPort();
        if (port != null) {
            stmt.bindString(4, port);
        }
 
        Long customId = entity.getCustomId();
        if (customId != null) {
            stmt.bindLong(5, customId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, IpDataBean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String text = entity.getText();
        if (text != null) {
            stmt.bindString(2, text);
        }
 
        String ip = entity.getIp();
        if (ip != null) {
            stmt.bindString(3, ip);
        }
 
        String port = entity.getPort();
        if (port != null) {
            stmt.bindString(4, port);
        }
 
        Long customId = entity.getCustomId();
        if (customId != null) {
            stmt.bindLong(5, customId);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public IpDataBean readEntity(Cursor cursor, int offset) {
        IpDataBean entity = new IpDataBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // text
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // ip
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // port
            cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4) // customId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, IpDataBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setText(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setIp(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setPort(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setCustomId(cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(IpDataBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(IpDataBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(IpDataBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "ipDataBeans" to-many relationship of FloderBean. */
    public List<IpDataBean> _queryFloderBean_IpDataBeans(Long customId) {
        synchronized (this) {
            if (floderBean_IpDataBeansQuery == null) {
                QueryBuilder<IpDataBean> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.CustomId.eq(null));
                floderBean_IpDataBeansQuery = queryBuilder.build();
            }
        }
        Query<IpDataBean> query = floderBean_IpDataBeansQuery.forCurrentThread();
        query.setParameter(0, customId);
        return query.list();
    }

}
